package com.chinatechstar.component.commons.result;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 构建分页信息
 *
 * @版权所有 上海至界信息科技有限公司 
 */
public class PaginationBuilder {

    private PaginationBuilder() {

    }

    public static Map<String, Object> buildResult(
        List<LinkedHashMap<String, Object>> resultList,
        long total,
        Integer currentPage,
        Integer pageSize) {
        LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
        resultMap.put("list", resultList);
        LinkedHashMap<String, Long> paginationMap = new LinkedHashMap<>();
        paginationMap.put("total", total);
        paginationMap.put("pageSize", (long) pageSize);
        paginationMap.put("current", (long) currentPage);
        resultMap.put("pagination", paginationMap);
        return resultMap;
    }

    public static Map<String, Object> buildResult(
        List<LinkedHashMap<String, Object>> resultList) {
        LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
        resultMap.put("list", resultList);
        return resultMap;
    }

    public static Map<String, Object> buildResultByObjList(
        List<? extends Object> resultList,
        long total,
        Integer currentPage,
        Integer pageSize) {
        LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
        resultMap.put("list", resultList);
        LinkedHashMap<String, Long> paginationMap = new LinkedHashMap<>();
        paginationMap.put("total", total);
        paginationMap.put("pageSize", (long) pageSize);
        paginationMap.put("current", (long) currentPage);
        resultMap.put("pagination", paginationMap);
        return resultMap;
    }

    public static Map<String, Object> buildResult(
            List<LinkedHashMap<String, Object>> resultList,
            long total,
            Integer currentPage,
            Integer pageSize,
            String type) {
        LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
        resultMap.put("list", resultList);
        LinkedHashMap<String, Long> paginationMap = new LinkedHashMap<>();
        paginationMap.put("total", total);
        paginationMap.put("pageSize", (long) pageSize);
        paginationMap.put("current", (long) currentPage);
        resultMap.put("pagination", paginationMap);
        resultMap.put("type", type);
        return resultMap;
    }
}
